package com.mercury.service;

import com.alibaba.fastjson.JSONObject;
import com.mercury.dao.IPcgiftaddressDao;
import com.mercury.entity.Pcgiftaddress;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class PcgiftaddressService {

    @Autowired
    IPcgiftaddressDao pcgiftaddressDao;

    public void create(JSONObject json) {
        Pcgiftaddress model = new Pcgiftaddress();
        model.setGuid(new SimpleDateFormat("yyyyMMddHHmmssSS").format(new Date()) + "0001");
        model.setName(json.getString("name"));
        model.setMobileNo(json.getString("mobileNo"));
        model.setAddress(json.getString("address"));
        model.setOpenId(json.getString("openId"));
        model.setCreateTime(new Date());
        pcgiftaddressDao.create(model);
    }

    public Pcgiftaddress getAddressByOpenId(String openId){
        return pcgiftaddressDao.getAddressByOpenId(openId);
    }
}
